package yxy.game.pm2.active.module.subordinateclass.weeklycard;

import yxy.cherry.data.bean.actweekcarkgift;
import yxy.game.pm2.active.module.actdata.ActDataCenter;
import yxy.game.pm2.module.daily.DailyModule;
import yxy.game.pm2.module.tip.TipHandle;
import yxy.game.pm2.module.tip.TipType;

import java.util.ArrayList;
import java.util.Map;

/**
 * 周卡活动 - 许愿
 * @author Dell
 *
 */
public class WeeklyWish {

	//bean ---------------------------------------------------------------------
	
	public static int selectnum = 3;	//选中数量
	
	private ArrayList<Integer> ids = new ArrayList<Integer>();			//表格id
	private ArrayList<Integer> unlockids = new ArrayList<Integer>();	//解锁ids
	private ArrayList<Integer> Selectids = new ArrayList<Integer>();	//选中ids
	
	public ArrayList<Integer> getIds() {
		return ids;
	}
	public void setIds(ArrayList<Integer> ids) {
		this.ids = ids;
	}
	public ArrayList<Integer> getUnlockids() {
		return unlockids;
	}
	public void setUnlockids(ArrayList<Integer> unlockids) {
		this.unlockids = unlockids;
	}
	public ArrayList<Integer> getSelectids() {
		return Selectids;
	}
	public void setSelectids(ArrayList<Integer> selectids) {
		Selectids = selectids;
	}
	
	//func ------------------------------------------------------------
	
	public static WeeklyWish create(String playercode) {
		WeeklyWish ww = new WeeklyWish();
		
		Map<String, actweekcarkgift> awcgmap = ActDataCenter.getAllData(actweekcarkgift.class, playercode);
		for(actweekcarkgift data : awcgmap.values()) {
			ww.getIds().add(data.getId());
			if(data.getCondition1() == 0 && data.getCondition2() == 0) {
				ww.getUnlockids().add(data.getId());
			} 
		}
		
		return ww;
	}
	
	
	public void update(String playercode , int pay) {
		if(getUnlockids().size() == getIds().size()) {
			return;
		}
		
		DailyModule dm = DailyModule.get(playercode);
		int exp = dm.getExp();
		
		for(int id : getIds()) {
			if(getUnlockids().contains(id)) {
				continue;
			}
			
			actweekcarkgift awc = ActDataCenter.getData(id, actweekcarkgift.class, playercode);
			if(awc == null) {
				continue;
			}
			
			int condition1 = awc.getCondition1();
			int condition2 = awc.getCondition2();
			
			//TODO：临时
			if(exp < condition1) {
				continue;
			}
			
			if(condition2 == 1 && pay == 0) {
				continue;
			}
			
			getUnlockids().add(id);
		}
	}
	
	/**
	 * 转天刷新
	 */
	public void refresh() {
		setSelectids(new ArrayList<Integer>());
		setUnlockids(new ArrayList<Integer>());
	}
	
	/**
	 * 重置
	 */
	public void reset(String playercode) {
		WeeklyWish ww = create(playercode);
		
		setIds(ww.getIds());
		setSelectids(ww.getSelectids());
		setUnlockids(ww.getUnlockids());
	}
	
	public void check(String playercode) {
		if(getSelectids().size() == 0) {
			new TipHandle().updateTip(playercode, TipType.活动_周卡_许愿未锁定, true);
			return;
		}
		new TipHandle().updateTip(playercode, TipType.活动_周卡_许愿未锁定, false);
	}
	
}
